// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   recorder_ok.java

package oa.meeting;

import com.jspsmart.upload.*;
import include.nseer_cookie.counter;
import include.nseer_cookie.getFileLength;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class recorder_ok extends HttpServlet
{

	public recorder_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 oa_db = new nseer_db_backup1(dbApplication);
			if (oa_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				String meeting_ID = request.getParameter("meeting_ID");
				try
				{
					mySmartUpload.upload();
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					String meeting_subject = mySmartUpload.getRequest().getParameter("meeting_subject");
					String dealwith_register = mySmartUpload.getRequest().getParameter("dealwith_register");
					String dealwith_register_ID = mySmartUpload.getRequest().getParameter("dealwith_register_ID");
					String ifplaning = mySmartUpload.getRequest().getParameter("ifplaning");
					int n = 0;
					String sql2 = (new StringBuilder("select * from oa_meeting where meeting_ID='")).append(meeting_ID).append("' and check_tag='1'").toString();
					ResultSet rs2 = oa_db.executeQuery(sql2);
					if (!rs2.next())
					{
						response.sendRedirect("oa/meeting/recorder_ok_a.jsp");
					} else
					{
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							SmartFile file = mySmartUpload.getFiles().getFile(i);
							if (file.isMissing())
							{
								file_name[i] = "";
							} else
							{
								int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount");
								count.write((String)dbSession.getAttribute("unit_db_name"), "oaAttachmentcount", filenum);
								file_name[i] = (new StringBuilder(String.valueOf(filenum))).append(file.getFileName()).toString();
								file.saveAs((new StringBuilder(String.valueOf(path))).append("oa/file_attachments/").append(filenum).append(file.getFileName()).toString());
							}
						}

						String content = mySmartUpload.getRequest().getParameter("content");
						String sql1 = (new StringBuilder("update oa_meeting set dealwith_register='")).append(dealwith_register).append("',dealwith_register_ID='").append(dealwith_register_ID).append("',content='").append(content).append("',attachment2='").append(file_name[0]).append("',ifplaning='").append(ifplaning).append("',check_tag='2' where meeting_ID='").append(meeting_ID).append("'").toString();
						oa_db.executeUpdate(sql1);
						if (ifplaning.equals("0"))
						{
							String sql3 = (new StringBuilder("insert into oa_planing(meeting_subject) values('")).append(meeting_subject).append("')").toString();
							oa_db.executeUpdate(sql3);
						}
						response.sendRedirect("oa/meeting/recorder_ok_b.jsp");
					}
					oa_db.commit();
					oa_db.close();
				}
				catch (Exception ex)
				{
					response.sendRedirect((new StringBuilder("oa/meeting/recorder_ok_c.jsp?meeting_ID=")).append(meeting_ID).toString());
				}
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
